﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Jzy.Core.Utility;

namespace FortuneHeavenCommon.ComMethod
{
    public  class WebCookie
    {
        private static System.Web.HttpContext Current
        {
            get
            {
                return System.Web.HttpContext.Current;
            }
        }

        public HttpCookieCollection Cookie
        {
            get
            {
                return Current.Request.Cookies;
            }
        }

        public static string LoginUser
        {
            get
            {
                return (Current.Request.Cookies["LoginUser"] == null) ? null : Current.Request.Cookies["MemberLoginName"].Value;
            }
            set
            {
                HttpCookie cookie = new HttpCookie("LoginUser", value);
                cookie.Expires = DateTime.Now.AddHours(10);
                Current.Response.Cookies.Add(cookie);

            }
        }

        public static string LoginPwd
        {
            get
            {
                return (Current.Request.Cookies["LoginPwd"] == null) ? null : StrUtil.DecryptDES(Current.Request.Cookies["MemberPassword"].Value);
            }
            set
            {
                HttpCookie cookie = new HttpCookie("LoginPwd", StrUtil.EncryptDES(value));
                Current.Response.Cookies.Add(cookie);
            }
        }

        public static void Clear()
        {
            HttpCookie cookie = new HttpCookie("LoginUser");
            cookie.Expires = DateTime.Now.AddDays(-1);
            Current.Response.Cookies.Add(cookie);

            cookie = new HttpCookie("LoginPwd");
            cookie.Expires = DateTime.Now.AddDays(-1);
            Current.Response.Cookies.Add(cookie);
        }
    }
}
